home *** CD-ROM | disk | FTP | other *** search
-
- Listing 3
-
- uses
- scan;
-
- var
- tc : token_code;
-
- function expr(var e : integer) : boolean;
- var
- op : token_code;
- begin
- expr := FALSE;
- if tc <> TC_INT then
- exit;
- e := int_value;
- tc := get_token;
- while tc in [TC_ADD, TC_SUB, TC_MUL, TC_DIV] do
- begin
- op := tc;
- tc := get_token;
- if tc <> TC_INT then
- exit;
- case op of
- TC_ADD:
- e := e + int_value;
- TC_SUB:
- e := e - int_value;
- TC_MUL:
- e := e * int_value;
- TC_DIV:
- e := e div int_value;
- end;
- tc := get_token;
- end;
- expr := TRUE;
- end;
-
- var
- result : integer;
-
- begin
- start_scan;
- tc := get_token;
- while tc <> TC_EOF do
- begin
- if expr(result) and (tc = TC_EOL) then
- writeln('= ', result)
- else
- begin
- writeln('*** ERROR ***');
- restart_scan;
- end;
- tc := get_token;
- end;
- end.
-
-